﻿using AutoMapper.Internal.Mappers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace Himp.Platform
{
    /// <summary>
    /// 
    /// </summary>
    public class AppBiznodeService : CrudAppService<AppBiznode, AppBiznodeDto, Guid, AppBiznodeInput, AppBiznodeCreateDto, AppBiznodeUpdateDto>
    {
        /// <summary>
        /// 
        /// </summary>
        private IRepository<AppBiznode, Guid> _AppBiznodeRepository;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="projectConfigRepository"></param>
        public AppBiznodeService(IRepository<AppBiznode, Guid> AppBiznodeRepository) : base(AppBiznodeRepository)
        {
            _AppBiznodeRepository = AppBiznodeRepository;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public override async Task<PagedResultDto<AppBiznodeDto>> GetListAsync(AppBiznodeInput input)
        {
            var iQuery = await _AppBiznodeRepository.GetQueryableAsync();

            if (input.Pi == 0)
            {
                var itemsDto = ObjectMapper.Map<List<AppBiznode>, List<AppBiznodeDto>>(iQuery.ToList());

                return new PagedResultDto<AppBiznodeDto>(itemsDto.Count, itemsDto);
            }
            else
            {
                var totalCount = iQuery.Count();
                var items = iQuery.Page(input.Pi, input.Ps);
                var itemsDto = ObjectMapper.Map<List<AppBiznode>, List<AppBiznodeDto>>(items.ToList());

                return new PagedResultDto<AppBiznodeDto>(totalCount, itemsDto);
            }
        }
    }
}
